package cp4.req;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class DownloadServlet extends HttpServlet {

    int count = 2;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String referer = req.getHeader("Referer");// 获取访问来源
        resp.setContentType("text/html;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();
        if (referer == null || !referer.toLowerCase().contains("localhost:8080")) {
            out.println("请求非法");
        }else{
            //
            resp.sendRedirect("/a.zip");
        }
    }
}
